import json

from PyQt6.QtWidgets import QDialog
from PyQt6.uic import loadUi

import Global
from Script.GameFun import GameFun
from UI.DataDialog import Ui_DataDialogClass

class DataDialog(QDialog, Ui_DataDialogClass):
    def __init__(self, parent=None,m_currentRow=None):
        super().__init__(parent)
        #loadUi("UI/DataDialog.ui", self)
        self.setupUi(self)
        self.m_currentRow=m_currentRow
        self.btn_GetBag.clicked.connect(self.btn_GetBag_Clicked)
        self.btn_GetBagCanTrade.clicked.connect(self.GetBagCanTrade_Clicked)
    def btn_GetBag_Clicked(self):
        text = json.dumps(Global.G_Game[self.m_currentRow].Info,indent=4)
        self.textData.setText(text)
    def GetBagCanTrade_Clicked(self):
        monsters = sorted(Global.G_Game[self.m_currentRow].Info["monster"],
                                                      key=lambda x: (x['star'], x['level']), reverse=True)
        text =""
        for key,monster in enumerate(monsters):
            id = monster["id"]
            star= monster["star"]
            level =monster["level"]
            template = monster["base"]["template"]
            name,school = GameFun.GetMonsterConfigInfoById(self.m_currentRow,template)
            text +=f"ID:{id}\t星级:{star}\t等级:{level}\t类型:{school}\t名称:{name}\n"
        self.textData.setText(text)